/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.runtime.component
{
	import flash.display.Graphics;
	import flash.display.Shape;
	import flash.display.Sprite;
	
	import mx.controls.DataGrid;
	import mx.controls.listClasses.ListBaseContentHolder;
	import mx.core.FlexShape;
	
	public class BOPDatagrid extends DataGrid
	{
		public function BOPDatagrid()
		{
			super();
		}
		private var _rowColorFunction:Function;

		public function set rowColorFunction(f:Function):void
		{
			this._rowColorFunction=f;
		}

		public function get rowColorFunction():Function
		{
			return this._rowColorFunction;
		}

		override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
		{
			if (this.rowColorFunction != null)
			{
				if (dataProvider)
				{
					if (dataIndex < this.dataProvider.length)
					{
						var item:Object=this.dataProvider.getItemAt(dataIndex);
						color=this.rowColorFunction.call(this, item, color);
					}
				}
			}
//			var wd:Number = 0;
//			if(isNaN(contentHolder.width)){
//				wd = contentHolder.width;
//			}
			super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
//			EDIApplication.outputDebug((s.toString()));
//			var contentHolder:ListBaseContentHolder=ListBaseContentHolder(s.parent);
//			EDIApplication.outputDebug("contentHolder: "+contentHolder.toString());
//			EDIApplication.outputDebug("width: "+contentHolder.width.toString());
//			EDIApplication.outputDebug("height: "+height.toString());
//			var background:Shape;
//			if (rowIndex < s.numChildren)
//			{
//				background=Shape(s.getChildAt(rowIndex));
//			}
//			else
//			{
//				background=new FlexShape();
//				background.name="background";
//				s.addChild(background);
//			}
//
//			background.y=y;
//
//			// Height is usually as tall is the items in the row, but not if
//			// it would extend below the bottom of listContent
//			var height:Number=Math.min(height, contentHolder.height - y);
//
//			var g:Graphics=background.graphics;
//			g.clear();
//			g.beginFill(color, getStyle("backgroundAlpha"));
//			g.drawRect(0, 0, isNaN(contentHolder.width)?100:contentHolder.width, height);
//			g.endFill();

		}
//		override protected function updateDisplayList(unscaledWidth:Number,
//                                                  unscaledHeight:Number):void{
//                                                  	super.updateDisplayList(unscaledWidth,unscaledHeight);
//                                                  }
//		override protected function drawRowBackground(s:Sprite, rowIndex:int, y:Number, height:Number, color:uint, dataIndex:int):void
//		{
//			if (rowColorFunction != null)
//			{
//				//从dataProvider中获取当前item
//				var item:Object;
//				if (dataIndex < dataProvider.length)
//				{
//					item=dataProvider[dataIndex];
//				}
//				if (item)
//				{ //如果当前item存在，从rowColorFunction中获取行的颜色
//					color=rowColorFunction(item, rowIndex, dataIndex, color);
//				}
//			}
//			//调用父类方法设置当前行颜色
//			super.drawRowBackground(s, rowIndex, y, height, color, dataIndex);
//		}


	}
}